package com.dayuanit.dy15.lesson27.demo2;

public class Test {
    public static void main(String[] args) {
        //多线程 为什么使用多线程？一个字：快

        //创建一个线程，启动线程使用start方法。线程启动后，线程不会立刻得到CPU的执行，而是会被操作系统调度，然后给CPU执行。执行的时候
        //执行的是线程的run方法。
        Thread thread = new Thread();
        thread.start();

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Thread run()");
            }
        });
        t2.start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Thread run2()");
            }
        }).start();

        new Thread(() -> System.out.println("Thread.run3()")).start();

        //Runnable本质上定义线程要做的业务
        Runnable runnable = new Runnable(){
            @Override
            public void run() {
                System.out.println("搬砖");
            }
        };

        Thread tom = new Thread(runnable);
        Thread bob = new Thread(runnable);
        Thread eee = new Thread(runnable);
        tom.start();
        bob.start();


        Thread threadTom = new ThreadTom();
        Thread threadBob = new ThreadBob();

        threadTom.start();
        threadBob.start();

    }
}
